<?php
namespace app\controllers;

class RetargetController extends AuthController
{
    public $currentHeader = 'header-operation';
    public $currentNav = 'operate-retarget-nav';
    public $pageTitle = '';

    public function init() {
        parent::init();
        $service = new \app\services\SolutionService();
        $retarget = $service->getRetargetTypes();
        $this->retargets = $retarget;
    }

    public function actionList() {
        $this->pageTitle = $this->t('retarget', 'Retarget List');
        return $this->show();
    }

    public function actionNewRetarget() {
        $this->pageTitle = $this->t('retarget', 'Add Retarget');
        return $this->show();
    }

    public function actionRetargetEdit () {
        $this->pageTitle = $this->t('retarget', 'Edit Retarget');
        $retargetSiteId = $this->I('id');
        $this->site = $this->M('RetargetSite', $retargetSiteId);
        return $this->show();
    }

    public function actionNewRetargetHandle() {
        $post = $this->I();
        if ($this->service->addNewRetarget($post)) {
            $this->OK($this->t('retarget', 'Add retarget successfully!'));
        }
        $this->NG($this->t('retarget', 'Add retarget failed!'));
    }

    public function actionRetargetEditHandle() {
        $post = $this->I();
        if ($this->service->addEditRetarget($post)) {
            $this->OK($this->t('retarget', 'Edit retarget successfully!'));
        }
        $this->NG($this->t('retarget', 'Edit retarget faile!'));
    }

    public function actionGetRetargets() {
        $retargets = $this->service->getAllRetargets(); 
        $this->jsonReturn(['data' => $retargets]);
    }
}// end of retarget controller declaration
